Expose mknodat/mkfifoat on Apple targets#1625
Conversation
macOS 13 added mknodat/mkfifoat system calls. Use the same weak-linking pattern as linkat/unlinkat/renameat: resolve the symbol at runtime via dlsym, and fall back to mknod/mkfifo when the symbol is unavailable and dirfd == AT_FDCWD.
macOS 13 and earlier are EOL. Use c::mknodat directly via libc without weak-linking, matching other platforms.
The use declarations for Dev and FileType were gated with cfg(not(apple)), causing compilation failures when mknodat became available on Apple. Remove apple from the exclusion list.
|
I think a fallback is needed for macOS ≤ 13 since Apple macOS targets are supported as far back as macOS 10.12, and there are also additional Apple platforms to consider such as tvOS and watchOS. It would also be good to add references for the newly exposed functions on Apple targets. For example, https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mkfifoat.2 |
|
Or add non-*at too for macOS? |
|
Right, the POSIX |
|
I'll revise this PR to restore weak-linking/runtime detection. When the symbol is unavailable, I'll only fall back to |
|
On second thoughts, we probably don't need to implement a fallback for the libc backend. We can just return the appropriate Err and let callers handle it. |
| // If we have `mknodat`, use it. | ||
| if let Some(libc_mknodat) = mknodat.get() { | ||
| return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev)); | ||
| } | ||
| Err(io::Errno::NOSYS) |
There was a problem hiding this comment.
| // If we have `mknodat`, use it. | |
| if let Some(libc_mknodat) = mknodat.get() { | |
| return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev)); | |
| } | |
| Err(io::Errno::NOSYS) | |
| let libc_mknodat = mknodat.get().ok_or(io::Errno::NOSYS)?; | |
| ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev)) |
Summary
rustix::fs::{mknodat, mkfifoat}on Apple targets, which were previously gated out withcfg(not(apple))mknodat/mkfifoatsystem calls;mkfifoatworks automatically as it delegates tomknodat